package pro.shuangxi.frame;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;

@Component
public class MainFrame extends Application implements ApplicationContextAware {
    static ApplicationContext context;
    static Stage stage;
    @Autowired
    ArrayList<Scene> scenes;



    @PostConstruct
    public void showFrame(){
        this.launch();
    }
    @Override
    public void start(Stage primaryStage) throws Exception {
        Group root = new Group();
        Scene scene = new Scene(root);
        VBox vbox = new VBox();
        Button datasource = new Button("");
        primaryStage.setWidth(350);
        primaryStage.setHeight(500);
        primaryStage.show();
        MainFrame.stage=primaryStage;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        MainFrame.context = applicationContext;
    }

    public static void toScence(Class<Scene> sceneClass){
        Scene scene = MainFrame.context.getBean(sceneClass);
        MainFrame.stage.setScene(scene);
    }



}
